package org.nuist.repository;

import org.nuist.pojo.VirtualMachine;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VirtualMachineRepository extends JpaRepository<VirtualMachine,Integer> {

    @Query(name = "findVirtualMachineById",nativeQuery = true,value = "select * from `web_shell`.virtual_machine where virtual_machine_id=:id")
    public VirtualMachine findVirtualMachineById(@Param("id") Integer id);


    @Query(name = "findFreeVirtualMachine",nativeQuery = true,value = "select * from `web_shell`.virtual_machine where is_occupied=false")
    public List<VirtualMachine> findFreeVirtualMachine();

    @Query(name = "findVirtualMachineByPort",nativeQuery = true,value = "select * from web_shell.virtual_machine where port=:port")
    public VirtualMachine findVirtualMachineByPort(@Param("port")String port);

}
